﻿using Microsoft.Xna.Framework;
using Tetris.Interfaces;
using Tetris.Utility;

namespace Tetris.Screens
{
    public class MainMenuScreen: MenuScreenBase
    {
        private readonly IGameManager _gameManager;

        public MainMenuScreen( IGameManager gameManager ): base( gameManager, Constants.Strings.MAIN_MENU )
        {
            _gameManager = gameManager;

            MenuEntry playGameMenuEntry = new MenuEntry( gameManager, Constants.Strings.PLAY_GAME );
            MenuEntry showNotificationMenuEntry = new MenuEntry(gameManager, "Show Notification Test");
            MenuEntry exitMenuEntry = new MenuEntry( gameManager, Constants.Strings.EXIT );
            

            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
            showNotificationMenuEntry.Selected += OnShowNotification;
            exitMenuEntry.Selected += OnCancel;

            MenuEntries.Add( playGameMenuEntry );
            MenuEntries.Add(showNotificationMenuEntry);
            MenuEntries.Add( exitMenuEntry );
        }

        private void OnShowNotification(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(_gameManager, new NotificationScreen("Achievement unlocked!", 3), null);
        }

        void PlayGameMenuEntrySelected( object sender, PlayerIndexEventArgs e )
        {
            LoadingScreen.Load( _gameManager, true, e.PlayerIndex, new GameplayScreen() );
        }

        protected override void OnCancel( PlayerIndex playerIndex )
        {
            _gameManager.Game.Exit();
        }
    }
}
